// You have generated a new plugin project without
// specifying the `--platforms` flag. A plugin project supports no platforms is generated.
// To add platforms, run `flutter create -t plugin --platforms <platforms> .` under the same
// directory. You can also find a detailed instruction on how to add platforms in the `pubspec.yaml` at https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms.

import 'dart:async';
import 'dart:io' show Platform;

import 'package:flutter/services.dart';
import 'package:flutter/foundation.dart' show kIsWeb;


class VUtil {
  static const MethodChannel _channel = const MethodChannel('vutil');

  static Future<String?> get platformVersion async {
    if(kIsWeb || !Platform.isAndroid) {
      return null;
    }
    final String? version = await _channel.invokeMethod('getPlatformVersion');
    return version??'';
  }

  static Future<bool?> setDataToSettings(String key, String value) async {
    if(kIsWeb || !Platform.isAndroid) {
      return null;
    }
    assert(key != null);
    final res = await _channel.invokeMethod('setDataToSettings', {'key': key, 'value': value});
    return res??false;
  }

  static Future<String?> getDataToSettings(String key, String defaultValue) async {
    if(kIsWeb || !Platform.isAndroid) {
      return null;
    }
    assert(key != null);
    final String? res = await _channel.invokeMethod('getDataToSettings', {'key': key, 'defaultValue': defaultValue});
    return res??'';
  }

  static Future<bool?> replaceWord(String ftlDir, String ftlName, String docPath) async {
    if(kIsWeb || !Platform.isAndroid) {
      return null;
    }
    final res = await _channel.invokeMethod('replaceWord',{'ftlDir':ftlDir, 'ftlName': ftlName, 'docPath': docPath});
    return res ?? false;
  }
  static Future<bool?> get isRoot async {
    if(kIsWeb || !Platform.isAndroid) {
      return null;
    }
    final isRoot = await _channel.invokeMethod('isRoot');
    return isRoot??false;
  }

  /// dir为Environment中的变量，如 Environment.DIRECTORY_DCIM
  static Future<bool?> saveToGallery(String filePath, {String? dir}) async {
    if(kIsWeb || !Platform.isAndroid) {
      return null;
    }
    final res = await _channel.invokeMethod('saveToGallery',{'filePath':filePath, 'dir': dir});
    return res??false;
  }

  static Future<bool?> openApp(String packageName, String activityPath) async {
    if(kIsWeb || !Platform.isAndroid) {
      return null;
    }
    final res = await _channel.invokeMethod('openApp',{'packageName':packageName, 'activityPath': activityPath});
    return res??false;
  }
}
